<template>
  <div class="home_Box">
    <!-- ============== 首页 ================= -->
    <el-container>
      <!-- ============== 头部 ================= -->
      <el-header>
        <el-row :gutter="20">
          <el-col :span="1">
            <span class="grid-content bg-purple">
              <img src="../../assets/狗子5.jpg" alt="" class="header_img" />
            </span>
          </el-col>
          <el-col :span="15">
            <span class="grid-content bg-purple-light">电商后台管理系统</span>
          </el-col>
          <el-col :span="8">
            <span class="grid-content bg-purple"
              ><el-button type="info" @click="back_btn"> 退出 </el-button></span
            >
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <!-- ============== 左边 ================= -->
        <!-- 
           @open="handleOpen"
            @close="handleClose"
         -->
        <el-aside width="200px" :width="isCollapse ? '65px' : '200px'">
          <!-- 折叠框 -->
          <div class="collapse" @click="isCollapse = !isCollapse">|||</div>
          <el-menu
            :collapse="isCollapse"
            class="el-menu-vertical-demo"
            :collapse-transition="false"
            :default-active="$route.name"
            :unique-opened="true"
            background-color="#333744"
            active-text-color="#ff0"
            text-color="#fff"
            :router="true"
          >
            <el-submenu
              index="1"
              :index="item.path + ''"
              v-for="item in menus"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="item2.path"
                v-for="item2 in item.children"
                :key="item2.id"
              >
                <i class="el-icon-menu"></i>
                {{ item2.authName }}
                <span slot="title"></span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- ============== 右边 ================= -->
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { MenusApi } from "../../http/api";
// import { MessageBox } from "element-ui";
export default {
  data() {
    return {
      // 左侧菜单是否折叠
      isCollapse: false,

      // 左侧菜单
      menus: [],
    };
  },
  methods: {
    // 请求数据列表
    async MenusList() {
      // const res = this.$API.MenusApi();
      // console.log("左侧数据列表:", res);
      const res = await MenusApi();
      this.menus = res;
      // console.log("左侧数据列表:", this.menus);
    },
    // 退出按钮
    back_btn() {
      this.$confirm("是否要退出, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // 清除本地token
          sessionStorage.removeItem("token");

          // 跳转登陆页面
          this.$router.push({ path: "/login" });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.MenusList();
  },
};
</script>

<style lang="scss" scoped>
.home_Box {
  height: 100%;
  ::v-deep .el-header {
    background-color: #333744;
    color: #fff;
    text-align: center;
    line-height: 60px;
    // line-height: 80px;

    .el-row {
      width: 100%;
      // background-color: #fff;
    }
    // 头部
    .bg-purple {
      box-sizing: border-box;
      // 图片
      .header_img {
        width: 60px;
        border-radius: 50%;
        float: left;
        margin-left: 10px;
        margin-top: 10px;
      }
    }
    // 退出按钮
    .back_btn {
      line-height: 40px;
      padding: 0 20px;
      background-color: #909399;
      border-radius: 5px;
      border: none;
      color: #fff;
    }
  }

  .bg-purple {
    float: right;
  }
  .bg-purple-light {
    font-size: 20px;
    float: left;
    margin-left: 120px;
  }

  // 折叠框
  .collapse {
    margin-top: 20px;
    height: 30px;
    line-height: 30px;
    color: #fff;
    text-align: center;
    background-color: #4a5163;
  }

  .el-aside {
    background-color: #333744;
    color: #333;
    // background-color: #d3dce6;
    // color: #333;
    // text-align: center;
    // line-height: 200px;
    // background-color: #333744;
  }

  .el-main {
  background-color: #e9eef3;
  // color: #333;
  // text-align: center;
  // line-height: 160px;
  // height: 100%;
  }
  .el-menu {
    border-right: none;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  // 最外层大盒子
  .el-container {
    height: 100%;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
}
</style>
